﻿<script>
    var code = getUrlParam("Code") || "";
    var appCode = getUrlParam("AppCode") || "";
    $(function () {
        $("#ToolBar").AspLinkToolBar();
        $(".H3Panel").BuildPanel({ excludeIDs: ["FuntionAclList"] });
        CreateLigerGrid(
            $("#FuntionAclList"),
            GetCategoryColumns(),
            $.Controller.FunctionNode.GetFunctionAclList,
            true,
             "98%",
             null, null, null,
             { code: code }
            );

        $("#divUser").SheetUser({ Editable: true, Visiable: true, Originate: true, OrgUnitVisible: true });

    })
    function GetCategoryColumns() {
        var userName = $.Lang("FunctionAcl.UserName");
        var view = $.Lang("GlobalButton.View");
        return [
           { display: "ObjectID", name: "ObjectID", hide: true },
           { display: userName, name: "UserID", width: '30%' },
           {
               display: view, name: "Run", width: 250, align: 'center', render: function (row) {
                   if (row.Run != "0") {
                       return "<img src='"+_PORTALROOT_GLOBAL+ "/WFRes/images/checked.gif' />";
                   }
                   else
                       return "<img src='"+_PORTALROOT_GLOBAL+ "/WFRes/images/unChecked.gif' />";
               }
           }
        ];
    }

    function AddFun() {

        var userId = $("#divUser").SheetUIManager().GetValue();
        if (!userId || !code) {
            $.H3Dialog.Warn({ content: $.Lang("msgGlobalString.SelectItem") });
            return;
        }
        $.ajax({
            url: $.Controller.FunctionNode.SaveFunctionAcl,
            type: 'post',
            dataType: "json",
            data: { userId: userId, code: code, appCode: appCode },
            success: function (result) {
                if (result.Success) {
                    reloadList();
                } else {
                    if (result.Extend) {
                        $.H3Dialog.Warn({ content: $.format($.Lang(result.Message), result.Extend) });
                    } else {
                        $.H3Dialog.Warn({ content: $.Lang(result.Message) });
                    }
                }
            }
        });
    }
    function reloadList() {
        var manager = $("#FuntionAclList").ligerGetGridManager();
        manager.reload();
    };
    function DeleteFun(obj) {
        var SelectItemName = $.Lang("msgGlobalString.SelectItem");
        var rows = H3GridManager.getSelectedRows();
        if (rows == null || rows.length == 0) {
            $.H3Dialog.Warn({ content: SelectItemName });
            return false;
        }
        var ids = "";
        for (var i = 0; i < rows.length; i++) {
            ids = ids + rows[i].ObjectID + ",";
        }
        if (ConfirmDel(obj)) {
            $.ajax({
                url: $.Controller.FunctionNode.DelFunctionAcl,
                type: 'post',
                dataType: "json",
                data: { ids: ids, code: code, appCode: appCode },
                success: function (result) {
                    if (result.Success) {
                        reloadList();
                    } else {
                        $.H3Dialog.Warn({ content: result.Message });
                    }
                }
            });
        }
    };

</script>
<div id="ToolBar">
    <!--<a href="#" id="lnkAdd" data-icon="fa fa-plus" onclick="AddFun()" data-lang="GlobalButton.Add">添加</a>-->
    <a onclick="return DeleteFun(this);" id="" data-icon="fa fa-minus" href="javascript:void(0)" data-lang="GlobalButton.Delete">删除</a>
</div>
<div class="H3Panel">
    <table>
        <tr>
            <td data-lang="FunctionAcl.NewManager">新管理员</td>
            <td style="width: 250px;">
                <div id="divUser" style="width: 200px;"></div>
            </td>
            <td>
                <a href="javascript:void(0)" id="lnkAdd" data-icon="fa fa-plus" onclick="AddFun()" data-lang="GlobalButton.Add">添加</a>
            </td>
        </tr>
    </table>
</div>
<div class="H3Panel">
    <div id="FuntionAclList"></div>
</div>